home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2008 February / PCWFEB08.iso / Software / Resources / Developers / XAMPP 1.5.4 / Windows installer / xampp-win32-1.5.4-installer.exe / xampp / phpMyAdmin / scripts / upgrade.pl < prev   
Encoding:
Perl Script  |  2006-01-17  |  4.9 KB  |  224 lines

  1. #!/usr/bin/perl
  2. #
  3. # $Id: upgrade.pl,v 1.7 2006/01/17 17:03:02 cybot_tm Exp $
  4. #
  5. # upgrade.pl - automatic phpmyadmin upgrader
  6. #
  7. #
  8. # 2005-05-08, swix@users.sourceforge.net:
  9. # - created script
  10. #
  11. # 2005-10-29  swix@users.sourceforge.net:
  12. # - some fixes & improvements
  13. #
  14.  
  15. use strict;
  16. my $source_url = "http://phpmyadmin.net/home_page/version.php";
  17.  
  18.  
  19. #
  20. # usage
  21. #
  22.  
  23. if (!$ARGV[0] || (($ARGV[0] eq "--force") && !$ARGV[1])) {
  24.     print "\n";
  25.     print "usage: $0 [--force] <target_directory>\n\n";
  26.     print "  The location specified by <target_directory> will be backed up and replaced\n";
  27.     print "  by the latest stable version of phpMyAdmin.\n";
  28.     print "  Your config.inc.php file will be preserved.\n\n";
  29.     exit(0);
  30. }
  31.  
  32. my $forced;
  33. my $targetdirectory;
  34.  
  35. if ($ARGV[0] eq "--force") {
  36.     $forced = 1;
  37.     $targetdirectory = $ARGV[1];
  38. } else {
  39.     $forced = 0;
  40.     $targetdirectory = $ARGV[0];
  41. }
  42.  
  43. if ($targetdirectory =~ /^(.*)\/$/) {
  44.     # remove trailing slash, if any
  45.     $targetdirectory = $1;
  46. }
  47.  
  48. if (!-d $targetdirectory) {
  49.     print "error: target directory ($targetdirectory) does not exists\n";
  50.     exit(0);
  51. }
  52.  
  53. if (!-f "$targetdirectory/config.inc.php") {
  54.     print "error: target directory doesn't seem to contain phpMyAdmin\n";
  55.     exit(0);
  56. }
  57.  
  58.  
  59. #
  60. # get current release information
  61. #
  62.  
  63. my $version;
  64. my $filename;
  65. my $directory;
  66. my $releasedate;
  67. my @urls;
  68. my @today;
  69. my $installedversion;
  70.  
  71. if (open(LATEST, "wget -o /dev/null -O - $source_url|")) {
  72.  
  73.     $version = <LATEST>; chomp($version);
  74.     $releasedate = <LATEST>; chomp($releasedate);
  75.     $filename = "phpMyAdmin-" . $version . ".tar.gz";
  76.     $directory = "phpMyAdmin-" . $version;
  77.  
  78.     my $i = 0;
  79.  
  80.     while (my $line = <LATEST>) {
  81.         chomp($line);
  82.         if ($line =~ /http/) {
  83.             $urls[$i++] = $line;
  84.         }
  85.     }
  86.  
  87.     close(LATEST);
  88.  
  89. } else {
  90.  
  91.     print "error: open of $source_url failed.\n";
  92.     exit(0);
  93.  
  94. }
  95.  
  96.  
  97. if (-d $directory) {
  98.     print "error: target directory ($directory) already exists, exiting\n";
  99.     exit(0);
  100. }
  101.  
  102. #
  103. # check the installed version
  104. #
  105.  
  106. if (open(DEFINES, $targetdirectory .'/libraries/Config.class.php')) {
  107.     my $versionStatus = 0;
  108.     $installedversion = "unknownversion";
  109.  
  110.     while (my $line = <DEFINES>) {
  111.  
  112.         next unless $line =~ /'PMA_VERSION',\ '(.*)?'\);$/;
  113.         $installedversion = $1;
  114.  
  115.         # take care of "pl", "rc" and "dev": dev < rc < pl
  116.  
  117.         my $converted_installedversion = $installedversion;
  118.         $converted_installedversion =~ s/dev/aaa/g;
  119.         $converted_installedversion =~ s/rc/bbb/g;
  120.         $converted_installedversion =~ s/pl/ccc/g;
  121.  
  122.         my $converted_version = $version;
  123.         $converted_version =~ s/dev/aaa/g;
  124.         $converted_version =~ s/rc/bbb/g;
  125.         $converted_version =~ s/pl/ccc/g;
  126.  
  127.         if ($converted_installedversion gt $converted_version && !$forced) {
  128.             print "Local version ($installedversion) newer than latest stable release ($version), not updating.  (use \"--force\")\n";
  129.             exit(0);
  130.  
  131.         } elsif ($installedversion eq $version && !$forced) {
  132.             print "Local version ($version) already up to date, not updating  (you can use \"--force\")\n";
  133.             exit(0);
  134.  
  135.         } else {
  136.             $versionStatus = 1;
  137.         }
  138.     }
  139.     if (!$versionStatus && !$forced) {
  140.         print "Old version could not be identified, not updating  (use \"--force\" if you are sure) \n";
  141.         exit(0);
  142.     }
  143. }
  144.  
  145. #
  146. # ask for confirmation
  147. #
  148.  
  149. print "\n";
  150. print "phpMyAdmin upgrade summary:\n";
  151. print "---------------------------\n";
  152. print "     phpMyAdmin Path: $targetdirectory\n";
  153. print "   Installed version: $installedversion\n";
  154. print "    Upgraded version: $version\n\n";
  155. print "Proceed with upgrade?  [Y/n] ";
  156. my $kbdinput = <STDIN>; chomp($kbdinput);
  157. if (lc(substr($kbdinput,0,1)) ne "y" && length($kbdinput) >= 1) {
  158.     print "Aborting.\n";
  159.     exit(0);
  160. } else {
  161.     print "Proceeding...\n\n";
  162. }
  163.  
  164.  
  165. #
  166. # get file
  167. #
  168.  
  169. if (!-f $filename) {
  170.  
  171.     print "getting phpMyAdmin $version\n";
  172.     foreach my $url (@urls) {
  173.  
  174.         print "trying $url...\n";
  175.         system("wget -o /dev/null $url");
  176.         if (-f $filename) {
  177.             print "-> ok\n";
  178.             last;
  179.         }
  180.     }
  181. } else {
  182.     print "already got $filename, not downloading\n";
  183. }
  184.  
  185.  
  186. if (!-f $filename) {
  187.     print "error: $filename download failed\n";
  188.     exit(0);
  189. }
  190.  
  191.  
  192.  
  193. #
  194. # setup
  195. #
  196.  
  197. print "installing...\n";
  198.  
  199. system("tar xzf $filename");
  200. if (!$directory) {
  201.     print "error: $directory still not exists after untar...\n";
  202.     exit(0);
  203. }
  204.  
  205. @today = localtime(time); $today[4]++; $today[5]+=1900;
  206. my $timestamp = sprintf("%04d%02d%02d%02d%02d", $today[5], $today[4], $today[3], $today[2], $today[1]);
  207.  
  208. my $backupdir = $targetdirectory . "-" . $timestamp . "-" . $installedversion;
  209. print "- backup directory: $backupdir\n";
  210.  
  211. system("cp $directory/config.inc.php $directory/config.inc-dist.php");
  212. print "- original distribution config.inc.php renamed to config.inc-dist.php\n";
  213.  
  214. system("cp $targetdirectory/config.inc.php $directory/config.inc.php");
  215. print "- previous config.inc.php copied to the new setup\n";
  216.  
  217. system("mv $targetdirectory $backupdir");
  218. system("mv $directory $targetdirectory");
  219. system("rm $filename");
  220.  
  221. print "\ndone!  phpMyAdmin $version installed in $targetdirectory\n";
  222. print "backup of your old installation in $backupdir\n";
  223. print "Enjoy! :-)\n\n";
  224.